#pragma once

#include "IXUIParser.h"
#include "XBaseObjImpl.h"

#include "IXConfigFile.h"
#include "XIntParserBase.h"
#include "IIntParserFilter.h"

#include <map>
#include <vector>

typedef std::map<XString, IIntParser*>   IntParserMap;
typedef std::vector<IIntParserFilter*>   IntParserFilterVector;

class CXUIParserImpl : public CXBaseObjImpl<IXUIParser>
{
    typedef CXBaseObjImpl<IXUIParser> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXUIParserImpl,
        superclass,
        gs_strGuidXSkin,
        IXUIParser,
        0);

public:
    CXUIParserImpl();
    virtual ~CXUIParserImpl();

public:
    // IXUIParser
    virtual IXControl*  STDMETHODCALLTYPE   CreateUI(IN LPCTSTR szUIPath, IXControl* pParent);
    virtual HRESULT     STDMETHODCALLTYPE   ApplyStyle(IN IXControl* pControl, IN LPCTSTR szStyle);

public:
    virtual void    STDMETHODCALLTYPE   OnFinalRelease();

protected:
    void        ReleaseData();

    // Get IIntParser*
    IIntParser* GetIntParser(LPCTSTR szName);

    // Create IXControl
    BOOL        CreateControlFromNode(OUT IXControl** ppResult, IN IXConfigNode* pNode, IN IXControl* pParent);

    // Filter IXControl
    BOOL        FilterControl(IN IXControl* pResult, IN IXConfigNode* pNode, IN IXControl* pParent);

    // Find the Node
    IXConfigNode* FindTheNode(IN IXConfigFile* pConfigFile, IN LPCTSTR szStylePath);

    IXConfigNode* FindOrGenerateNode(IXConfigFile* pConfigFile, IN LPCTSTR szStyle);

    BOOL    IsStylePath(IN LPCTSTR szStyle);

protected:
    LPVOID      m_pData;
    DWORD       m_dwSize;
    DWORD       m_dwRealSize;

    IntParserMap    m_IntParserMap;
    IntParserFilterVector   m_vctIntParserFilter;
};

